package com.woniuxy.hrp.mapper;

import com.woniuxy.hrp.entity.OrderUser;
import com.woniuxy.hrp.provider.OrderUserMapperSqlProvider;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.jdbc.SQL;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * @program: hrph
 * @InterfaceName OrderUserMapper
 * @description:就诊人DAO
 * @author: LRW
 * @create: 2022-08-28 01:33
 * @Version 1.0
 **/

public interface OrderUserMapper {

    /***
     * @description: 增：绑定就诊人
     * @param: orderUser
     * @return: void
     * @author Lrw
     * @date: 2022/8/28 14:31
     */
    @Insert("insert into hrp_orderuser values(null,#{patient.id},#{name},#{age},#{phone},#{address},#{gender},#{def})")
    void add(OrderUser orderUser);

    /***
     * @description: 删：根据id删除指定就诊人
     * @param: id
     * @return: void
     * @author Lrw
     * @date: 2022/8/28 15:55
     */
    @Delete("delete from hrp_orderuser where id=#{id}")
    void delete(int id);

    /*** 
     * @description: 查：根据患者id查就诊人
     * @param: patientId
     * @return: 指定患者绑定的就诊人集合
     * @author Lrw
     * @date: 2022/8/28 1:37
     */
    @Select("select o.* from hrp_patient p ,hrp_orderuser o where p.id=o.patient_id and o.patient_id=#{patient.id}")
    List<OrderUser> selectByPatientId(int patientId);

    /***
     * @description: 改：修改指定就诊人信息
     * @param: orderUser
     * @return: void
     * @author Lrw
     * @date: 2022/8/28 20:06
     */
    @UpdateProvider(type = OrderUserMapperSqlProvider.class, method = "updateOrderUser")
    void update(OrderUser orderUser);

    /**
     * desc: 根据id获取就诊人
     * @Param: [id]
     * @Return: [int]
     * @Author: caojieke
     * @Date: 2022/8/29 22:09
     */
    @Select("select * from hrp_orderuser where id=#{id}")
    @Result(column = "patient_id",property = "patient",one = @One(select = "com.woniuxy.hrp.mapper.PatientMapper.selectById"))
    OrderUser selectById(int id);

}
